<?php

namespace app\index\controller;

use think\Controller;

class Demo extends Controller
{
    public function index()
    {
        $weixin = new Weixin();

        $url = request()->domain() . $this->request->url();
        $js_config = $weixin->js_config($url);
        $this->assign('jsconfig', $js_config);

        return $this->fetch();
    }

    public function img()
    {
        if(!cmf_is_wechat()){
            $this->error('需要微信中打开');
        }

        $weixin = new Weixin();

        $url = request()->domain() . $this->request->url();
        $js_config = $weixin->js_config($url);
        $this->assign('jsconfig', $js_config);

        return $this->fetch();

    }

    /**
     * 验证身份证接口demo
     */
    public function chaeckIdCard()
    {
        $id_card = "412701199002283070";

        echo check_id_card($id_card);

    }

    /**
     * 微信接口--获取地址位置
     */
    public function getLocation()
    {
        if(!cmf_is_wechat()){
            $this->error('需要微信中打开');
        }


        return $this->fetch();
    }


    /**
     * 测试模板
     */
    public function testWxTemplete()
    {
        $weixin = new Weixin();

        $openid         = 'oTJius6kQ2hFOF66Dw0l5Xg-ICUM';
        $templete_id    = 'BWrP-c1uXNvLvO-YNDtbVGVd0iiP7O3LibkzXkHirTI';
        $url            = 'http://www.baidu.com';

        $data_arr['first']          = ['value'=>'你的宝贝已经完成付款','color'=>'#2ee4d1'];
        $data_arr['goods']          = ['value'=>'张弓十年','color'=>'#2ee4d1'];
        $data_arr['price']          = ['value'=>'124.00 元','color'=>'#2ee4d1'];
        $data_arr['num']            = ['value'=>'5 件','color'=>'#2ee4d1'];
        $data_arr['spec']           = ['value'=>'1*6','color'=>'#2ee4d1'];

        $re = $weixin->sentMsg($openid , $templete_id , $url ,$data_arr);
        if($re['errcode'] != 0){
            $this->error("错误代码".$re['errcode']);
        }
    }


    /**
     * 乘客发布
     */
    public function tripAdd()
    {
        $weixin = new Weixin();

        $openid         = 'oTJius6kQ2hFOF66Dw0l5Xg-ICUM';
        $templete_id    = 'Jxz9iOGhPUiGxX_S-4qzW19aeKY3qDOXhUCMOsARLcU';
        $url            = 'http://www.baidu.com';

        $data_arr['user_name']          = ['value'=>'亲爱的李先生，您的行程已发布，系统正在努力为你寻找顺路车主，请耐心等待~','color'=>'#ff8a5a'];
        $data_arr['begin_place']        = ['value'=>'周口市人民商场','color'=>'#1491cb'];
        $data_arr['end_place']          = ['value'=>'周口市周口师范学院','color'=>'#1491cb'];
        $data_arr['depart_time']        = ['value'=>'2018-05-12 18:30:55','color'=>'#1491cb'];
        $data_arr['number']             = ['value'=>'4','color'=>'#1491cb'];
        $data_arr['content']            = ['value'=>'有大件行李,需走高速，高速费由我承担','color'=>'#1491cb'];

        $re = $weixin->sentMsg($openid , $templete_id , $url ,$data_arr);
        if($re['errcode'] != 0){
            $this->error("错误代码".$re['errcode']);
        }
    }


    /**
     * 设置自定义菜单
     */
    public function setWxMenu()
    {
        $weixin = new Weixin();

        $access_token = $weixin->getAccessToken();

        $jsonmenu = '
        {
            "button":[
                {
                    "name":"天气预报",
                    "sub_button":[
                        {
                            "type":"view",
                            "name":"本地天气",
                            "url":"http://m.hao123.com/a/tianqi"
                        }
                    ]
                },
           
                {
                   "name":"顺风车简介",
                   "sub_button":[
                        {
                           "type":"click",
                           "name":"公司简介",
                           "key":"company"
                        },
                        {
                           "type":"click",
                           "name":"趣味游戏",
                           "key":"游戏"
                        },
                        {
                            "type":"click",
                            "name":"讲个笑话",
                            "key":"笑话"
                        }
                   ]
               }
            ]
        }';

        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;

        $result = $weixin->https_request($url,$jsonmenu);

        print_r($result);



    }





}
